package main

import (
	_ "database/sql/driver"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"gorm.io/gorm"
	"os"
	"test/common"
	"test/routes"
)

//type People struct {
//	gorm.Model
//	Name string `gorm:"type:varchar(20);not null"`
//	Telephone string `gorm:"varchar(11);not null;unique"`
//	Password string `gorm:“size:255;not null"`
//}

var db *gorm.DB
func main() {
	InitConfig()
	db = common.InitDB()
	//user := peoples{sno: 2,sname: "ming"}
	//result := db.Create(&user)
	//fmt.Println(result)
	r := gin.Default()
	r = routes.CollectRoute(r)
	port := viper.GetString("server.port")
	if port != "" {
		panic(r.Run(":"+port))
	}
	panic(r.Run())// listen and serve on 0.0.0.0:8080
}

func InitConfig() {
	workDir,_ := os.Getwd()
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir+"/conf")
	err := viper.ReadInConfig()
	if err != nil {

	}
}
